<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Makes the next row in a result set available for reading</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sqlsrv-fetch-object.html">sqlsrv_fetch_object</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlsrv-field-metadata.html">sqlsrv_field_metadata</a></div>
 <div class="up"><a href="ref.sqlsrv.html">SQLSRV 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.sqlsrv-fetch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlsrv_fetch</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_fetch</span> &mdash; <span class="dc-title">Makes the next row in a result set available for reading</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sqlsrv-fetch-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>sqlsrv_fetch</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Makes the next row in a result set available for reading. Use 
   <span class="function"><a href="function.sqlsrv-get-field.html" class="function">sqlsrv_get_field()</a></span> to read the fields of the row.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.sqlsrv-fetch-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">stmt</code></em></dt>

     <dd>

      <p class="para">
       A statement resource created by executing <span class="function"><a href="function.sqlsrv-query.html" class="function">sqlsrv_query()</a></span> 
       or <span class="function"><a href="function.sqlsrv-execute.html" class="function">sqlsrv_execute()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">row</code></em></dt>

     <dd>

      <p class="para">
       The row to be accessed. This parameter can only be used if the specified 
       statement was prepared with a scrollable cursor. In that case, this parameter 
       can take on one of the following values:
       <ul class="simplelist">
        <li class="member">SQLSRV_SCROLL_NEXT</li>
        <li class="member">SQLSRV_SCROLL_PRIOR</li>
        <li class="member">SQLSRV_SCROLL_FIRST</li>
        <li class="member">SQLSRV_SCROLL_LAST</li>
        <li class="member">SQLSRV_SCROLL_ABSOLUTE</li>
        <li class="member">SQLSRV_SCROLL_RELATIVE</li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">offset</code></em></dt>

     <dd>

      <p class="para">
       Specifies the row to be accessed if the row parameter is set to
       <strong><code>SQLSRV_SCROLL_ABSOLUTE</code></strong> or
       <strong><code>SQLSRV_SCROLL_RELATIVE</code></strong>. Note that the first row in
       a result set has index 0.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-fetch-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> if the next row of a result set was successfully retrieved, 
   <strong><code>FALSE</code></strong> if an error occurs, and <strong><code>NULL</code></strong> if there are no more rows in the result set.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.sqlsrv-fetch-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2114">
    <p><strong>Example #1 <span class="function"><strong>sqlsrv_fetch()</strong></span> example</strong></p>
    <div class="example-contents"><p>
    The following example demonstrates how to retrieve a row with 
    <span class="function"><strong>sqlsrv_fetch()</strong></span> and get the row fields with 
    <span class="function"><a href="function.sqlsrv-get-field.html" class="function">sqlsrv_get_field()</a></span>.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$serverName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"serverName\sqlexpress"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$serverName</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$connectionInfo</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;Name,&nbsp;Comment&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM&nbsp;Table_1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE&nbsp;ReviewID=1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_query</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Make&nbsp;the&nbsp;first&nbsp;(and&nbsp;in&nbsp;this&nbsp;case,&nbsp;only)&nbsp;row&nbsp;of&nbsp;the&nbsp;result&nbsp;set&nbsp;available&nbsp;for&nbsp;reading.<br /></span><span style="color: #007700">if(&nbsp;</span><span style="color: #0000BB">sqlsrv_fetch</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Get&nbsp;the&nbsp;row&nbsp;fields.&nbsp;Field&nbsp;indeces&nbsp;start&nbsp;at&nbsp;0&nbsp;and&nbsp;must&nbsp;be&nbsp;retrieved&nbsp;in&nbsp;order.<br />//&nbsp;Retrieving&nbsp;row&nbsp;fields&nbsp;by&nbsp;name&nbsp;is&nbsp;not&nbsp;supported&nbsp;by&nbsp;sqlsrv_get_field.<br /></span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_get_field</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">:&nbsp;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$comment&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_get_field</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$comment</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 
 <div class="refsect1 seealso" id="refsect1-function.sqlsrv-fetch-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.sqlsrv-get-field.html" class="function" rel="rdfs-seeAlso">sqlsrv_get_field()</a> - Gets field data from the currently selected row</span></li>
    <li class="member"><span class="function"><a href="function.sqlsrv-fetch-array.html" class="function" rel="rdfs-seeAlso">sqlsrv_fetch_array()</a> - Returns a row as an array</span></li>
    <li class="member"><span class="function"><a href="function.sqlsrv-fetch-object.html" class="function" rel="rdfs-seeAlso">sqlsrv_fetch_object()</a> - Retrieves the next row of data in a result set as an object</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sqlsrv-fetch-object.html">sqlsrv_fetch_object</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlsrv-field-metadata.html">sqlsrv_field_metadata</a></div>
 <div class="up"><a href="ref.sqlsrv.html">SQLSRV 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
